package com.jiajia.server.exception;

import com.jiajia.server.pojo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author ZSJia
 * @date 2021/8/13 013 - 11:23
 */
@RestControllerAdvice
public class GoobalException {

    @ExceptionHandler({SQLException.class})
    public RespBean mysqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return  RespBean.error("该数据有关联数据，操作失败");
        }
        return RespBean.error("数据异常，操作失败");
    }
}
